package com.dd.ljzapplication.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.dd.ljzapplication.adapter.BaseRVAdapter06;

/**
 * Created by LiJZ on 2017/1/16.
 */

public class CustomRecyclerView extends RecyclerView {

	public CustomRecyclerView(Context context) {
		super(context);
	}

	public CustomRecyclerView(Context context, @Nullable AttributeSet attrs) {
		super(context, attrs);
	}

	public CustomRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent e) {
		return super.onInterceptTouchEvent(e);
//		return true;
	}

	float lastY;

	@Override
	public boolean onTouchEvent(MotionEvent e) {
		int actionMasked = MotionEventCompat.getActionMasked(e);
		switch (actionMasked) {
			case MotionEvent.ACTION_DOWN:
				lastY = e.getRawY();
				break;
			case MotionEvent.ACTION_MOVE:
				float delatY = e.getRawY() - lastY;
				lastY = e.getRawY();
				View header = ((BaseRVAdapter06) getAdapter()).getHeader();
				if (header.getParent()!=null) {
					ViewGroup.LayoutParams layoutParams = header.getLayoutParams();
					int height = layoutParams.height;
					if (delatY > 0 || height > 0) {
						layoutParams.height = (int) (delatY / 3 + height);
						header.setLayoutParams(layoutParams);
						if (height > 0) {
							return false;
						}
					}
				}

				break;
			case MotionEvent.ACTION_UP:
				break;
		}
		return super.onTouchEvent(e);
//		return false;
	}
}
